<?php
/**
 * Created by PhpStorm.
 * User: guokunsheng
 * Date: 2018/6/12
 * Time: 11:46
 */
namespace app\common\model;


use think\Cache;

/**
 * 档案-档案袋 关系  中间表
 * Class RecodeCat
 * @package app\common\model
 */
class RecodeCat extends Base
{
    protected $table = 'wechat_backup_07_18_14_43_00.app_recode_cat';

    /**
     * 获取当前用户的档案袋
     */
    public function getRecodeCat($map=[])
    {
        $uid = $map['uid'];
        $data = false;

        if ($this->cache_on>=1)
        {
            $data = Cache::get('recode_cat_'.$uid);
        }

        if ($data ===false)
        {
            $data = $this->alias('rc')
                ->field('rc.cid,rc.rid')
                ->join('wechat_backup_07_18_14_43_00.app_recode r','rc.rid=r.id','INNER')
                ->where('r.uid',$uid)
                ->select();

            $data = json_decode(json_encode($data,true),true);

            if ($this->cache_on>=1)
            {
                Cache::set('recode_cat_'.$uid,$data,86400*3);
            }
        }

        return $data;
    }

    public function getRecodeCatId($map=[])
    {
        $uid = $map['uid'];
        $rid = $map['rid'];
        $data = $this->getRecodeCat(['uid'=>$uid]);

        $cid =null;

        foreach ($data as $v)
        {
            if ($v['rid']==$rid)
            {
                $cid = $v['cid'];
            }
        }

        return $cid;
    }


}
